< previous page page_130 next page >

Page 130
Laying Out the Control and Building the Maintenance Routines
For this example, you only need one visual control on your custom controlthe TextBox control. Place a single TextBox control on your UserControl form. Don't worry about its size or placement. You set all that up in code. After you add the TextBox control to the UserControl form space, it should look like the UserControl in Figure 5.10
0130-01.jpg
Figure 5.10.
Adding the TextBox control to
the UserControl form space.
The next step is to add code that allows for resizing the control (at design time or runtime), and some initialization code that runs the first time the control is added to a Visual Basic form. First, add the code in Listing 5.10 to your project. This handles resizing of the control.
Type.gifListing 5.10. Adding code to the UserControl_Resize event.
Private Sub UserControl_Resize()
    '
    ' make textbox fill the control space
    '
    With Text1
        .Left = 1
        .Top = 1
        .Height = UserControl.Height
        .Width = UserControl.Width
    End With
    '
End Sub
Now, each time the user resizes the control, the textbox stretches to fill the space.
Next you need to add a few lines of code to the InitProperties event. This code sets the default size of the control when it is placed on a form. Enter the code from Listing 5.11 into the UserControl_InitProperties event.

 
< previous page page_130 next page >

If you like this book, buy it!